import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/pages/book/miniBook.dart';
import 'package:ichinesereader/pages/book/minibookForWeb.dart';

class MiniBookDialog extends StatefulWidget {
  MiniBookDialog(
      {Key? key,
      required this.btitle,
      required this.bid,
      required this.bcode,
      required this.lang,
      required this.language,
      this.assignmentId})
      : super(key: key);
  final String btitle;
  final String bid;
  final String bcode;
  final String lang;
  final String language;
  final String? assignmentId;

  @override
  _MiniBookDialog createState() => _MiniBookDialog();
}

class _MiniBookDialog extends State<MiniBookDialog> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
        content: Container(
      height: MediaQuery.of(context).size.width * 0.9,
      width: MediaQuery.of(context).size.width * 0.9,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          SizedBox(height: 15),
          if (GetPlatform.isWeb)
            Expanded(
                child: MiniBookForWebWebview(
              bookId: widget.bid,
              bookCode: widget.bcode,
              assignmentId: widget.assignmentId,
              bookTitle: widget.btitle,
            )),
          if (!GetPlatform.isWeb)
            Expanded(
              child: InAppWebViewAppMiniBookScreen(
                  bookId: widget.bid,
                  bookCode: widget.bcode,
                  bookTitle: widget.btitle,
                  lang: widget.lang,
                  language: widget.language,
                  assignmentId: widget.assignmentId),
            ),
          MaterialButton(
              color: Theme.of(context).colorScheme.primary,
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: Text('Close'.tr))
        ],
      ),
    ));
  }

  launchInWebViewWithJavaScript(String s) {}
}
